import api from '@/api'

jest.mock('@/api', () => ({
  book: {
    searchBook: jest.fn().mockResolvedValue({ data: [] })
  }
}))

describe('搜索性能测试套件', () => {
  test.concurrent('应处理100个并发请求', async () => {
    const concurrency = 100
    const requests = Array(concurrency).fill().map(() => 
      api.book.searchBook({ keyword: 'Vue' })
    )

    const start = Date.now()
    await Promise.all(requests)
    const duration = Date.now() - start

    console.log(`[性能] 处理 ${concurrency} 请求耗时: ${duration}ms`)
    expect(duration).toBeLessThan(5000) // 5秒阈值
  })

  test('响应时间应小于500ms', async () => {
    const start = Date.now()
    await api.book.searchBook({ keyword: '测试' })
    const duration = Date.now() - start
    
    expect(duration).toBeLessThan(500)
  })
})